{% extends "base_generic.html" %}
{% block script %}
<script type="text/javascript">

  function hideInfo(id){
    $('#'+id).hide();
  }
  
  function hideAllInfo(){
    {% for term in terms %}
      hideInfo('info-{{term.url}}');
    {% endfor %}
  }
  
  function MarkFavourite(termkey){
    $('#loader').show();
    title = $('#title').val();
    year = $('#year').val();
    url = '/markfavourite';
    $.getJSON(url,{key: termkey},
      function(data){
        if(data){
          if(data.type == 'fav1'){
            if(data.user=='irra'){
              $('#img-'+data.key).attr('src','/img/star-on1.gif');
            }else{
              $('#img-'+data.key).attr('src','/img/star-on2.gif');
            }
          }else if(data.type == 'fav2'){
            if(data.user=='irra'){
              $('#img-'+data.key).attr('src','/img/star-on2.gif');
            }else{
              $('#img-'+data.key).attr('src','/img/star-on1.gif');
            }
          }else{
            $('#img-'+data.key).attr('src','/img/star-off.gif');
          }
        }else{
          alert('There was a problem, try again later');
        }
    });
  }
</script>
{% endblock %}
{% block content %}
  <div id="primaryContentContainer">
    <div id="primaryContent">
        <div><h3><a href="#" onclick="$('#genrescontainer').toggle();return false;">Categories</a> | <a href="/vocabulary/printable/{{lang}}?page={{page}}">Print</a></h3></div>
        <div id="genrescontainer" style="display: none;">
        {% for atermtype in termtypes %}
         {% if forloop.first %}
           <ul class="menugenres">
         {% endif %}
         {% ifequal atermtype.url termtype.url %}
         <li> <strong>{{atermtype.name}}</strong></li>
         {% else %}
         <li><a href="/vocabulary/{{atermtype.url}}{% ifnotequal lang '' %}/{{lang}}{%endifnotequal %}">{{atermtype.name}}</a></li>
         {% endifequal %}
         {% if forloop.last %}
           </ul>
         {% endif %}
        {% endfor %}
        </div>
        {% if tag %}<h2>{{tag.name}}</h2>{% endif %}
    {% if login %}<h2><img src="/img/plus.png" border="0" /> <a href="/vocabulary/{{lang}}/new/{% if termtype %}?type={{termtype.url}}{% endif %}" class="add">Add new Term ({{terms|length}})</a></h2>{% endif %}
    {% for term in terms %}
    {% if forloop.first %}
     <table class="tablelist">
      <tr class="rowH"><th></th><th>Original</th><th>Spanish</th></tr>      
    {% endif %}
      <tr class="{{forloop.counter|zebra}}">
        <td>{% if login %}<a href="#" onclick="MarkFavourite('{{term.key}}');return false;">{% ifequal customuser.url 'irra' %}{% if term.fav1 %}<img id="img-{{term.key}}" src="/img/star-on1.gif" border="0"/></a>{% else %}{% if term.fav2 %}<img id="img-{{term.key}}" src="/img/star-on2.gif" border="0"/>{% else %}<img id="img-{{term.key}}" src="/img/star-off.gif" border="0"/>{% endif %}{% endif %}{% endifequal %}{% ifequal customuser.url 'alvaro' %}{% if term.fav2 %}<img id="img-{{term.key}}" src="/img/star-on1.gif" border="0"/></a>{% else %}{% if term.fav1 %}<img id="img-{{term.key}}" src="/img/star-on2.gif" border="0"/>{% else %}<img id="img-{{term.key}}" src="/img/star-off.gif" border="0"/>{% endif %}{% endif %}{% endifequal %}</a>{% endif %}</td>
        <td><a href="#" onclick="$('#info-{{term.url}}').toggle();return false;"><span class="prefixword">{{term.prefix}}</span>{{term.word}}</a></td>
        <td>{{term.translate}}</td>
      </tr>
      <tbody class="extrainfo" id="info-{{term.url}}">
      <tr>
        {% if login %}<td colspan="2">{% else %}<td colspan="3">{% endif %}{{term.termtype.name}}: {% for attribute in term.attributes %}{{attribute}}{% if not forloop.last %},{% endif %}{% endfor %}</td>
        {% if login %}<td><a href="/vocabulary/{{term.key}}/edit/"><img src="/img/edit.gif" border="0" /></a> <a href="/vocabulary/{{term.key}}/delete/" onclick="return confirm('are you sure do you want to delete \'{{term.word}}\'?');"><img src="/img/delete.gif" border="0" /></a></td>{% endif %}
      </tr>
      {% for tag in term.tags %}{% if forloop.first %}<tr><td colspan="3">{% endif %}<a href="/vocabulary/tags/{{tag|urlconversion}}/{{lang}}">{{tag|capfirst}}</a>{% if not forloop.last %} , {% endif %}{% if forloop.last %}</td></tr>{% endif %}{% endfor %}
      </tbody>
      {% ifnotequal term.translate2 '' %}<tr class="meaning2"><td></td><td></td><td>{{term.translate2}}</td></tr>{% endifnotequal %}
      {% ifnotequal term.translate3 '' %}<tr class="meaning3"><td></td><td></td><td>{{term.translate3}}</td></tr>{% endifnotequal %}


{% if forloop.last %}
      {% for apage in pages %}
        {% if forloop.first %}
          <tr class="pagination"><td colspan="3"><center>
        {% endif %}
        {% ifequal apage page %}
        <strong>{{apage}}</strong>
        {% else %}
        <span><a href="?page={{apage}}">{{apage}}</a></span>
        {% endifequal %}
        {% if forloop.last %}
          </center></td></tr>
        {% endif %}
      {% endfor %}

      {% for apagetext in pagestext %}
        {% if forloop.first %}
          <tr class="pagination"><td colspan="3"><center>
        {% endif %}
        {% ifequal forloop.counter page %}
        <strong>{{forloop.counter}} - ({{apagetext.first}} - {{apagetext.last}})</strong><br />
        {% else %}
        <span><a href="?page={{forloop.counter}}">{{forloop.counter}} - ({{apagetext.first}} - {{apagetext.last}})</a></span><br />
        {% endifequal %}
        {% if forloop.last %}
          </center></td></tr>
        {% endif %}
      {% endfor %}
      </table>
{% endif %}
     {%endfor%}
{% endblock %}
